package com.xzy.generic.bad.example.a;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 随着项目的迭代，系统各种逐渐出现了许多“模板化”的Event类。
 *
 * @author xzy.xiao
 * @date 2023/2/28  20:06
 */
class Main {
    public static void main(String[] args) throws InterruptedException {
        // 创建容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        // 注册事件监听器
        applicationContext.registerBean("eventAaaListener", AaaEventListener.class);
        applicationContext.registerBean("eventBbbListener", BbbEventListener.class);
        applicationContext.refresh();

        // 发布事件
        for (int i = 0; i < 3; i++) {
            AaaEventPublisher.sendInsertEvent(applicationContext);
            AaaEventPublisher.sendDeleteEvent(applicationContext);
            AaaEventPublisher.sendUpdateEvent(applicationContext);

            BbbEventPublisher.sendInsertEvent(applicationContext);
            BbbEventPublisher.sendDeleteEvent(applicationContext);
            BbbEventPublisher.sendUpdateEvent(applicationContext);
            Thread.sleep(1000);
        }
    }
}
